#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;

void test0(){
    vector<int> nums{1,2,3,4,5};
    /* int * p = nums.begin(); */
    vector<int>::iterator it = nums.begin();
    cout << *it << endl;
    auto it2 = nums.end();
    it2--;
    cout << *it2 << endl;

    cout << endl;
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    nums.push_back(10);
    cout << endl;
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    vector<int> nums2 = nums;
    cout << endl;
    cout << nums2.size() << endl;
    cout << nums2.capacity() << endl;

    nums.pop_back();
    cout << endl;
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    nums.shrink_to_fit();
    cout << endl;
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    nums.clear();
    cout << endl;
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;
}

void test1(){
    //如果需求是创建一个准备存放10个元素的vector
    //如果直接用有参构造
    //那么不仅仅会将存放元素的空间准备好
    //而且还会对元素进行初始化
    vector<int> nums(10);
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    //准备了存放元素的空间，但是没有初始化元素
    //相比从空的vector开始，一次一次往vector中存放元素
    //如果使用了reserve函数，
    //能够避免多次动态扩容，提高了效率
    cout << endl;
    vector<int> nums2;
    nums2.reserve(10);
    cout << nums2.size() << endl;
    cout << nums2.capacity() << endl;
}

int main(void){
    test1();
    return 0;
}
